package util

import (
	"fmt"
	"gateway"
	redisConnection "github.com/garyburd/redigo/redis"
	"io"
)

type Redis struct {
	Config gateway.Config
}

func (redis Redis) GetConnectionFromPool() (conn redisConnection.Conn, error error) {

	//minOpen := 5
	//maxOpen := 100
	//maxLifetime := 5 * time.Hour
	//pool, err := NewGenericPool(minOpen, maxOpen, maxLifetime, redis.createConnection)
	//if err != nil {
	//	log.Fatal(error)
	//}
	//conn, error := pool.Acquire()
	//if error != nil {
	//	log.Fatal(error)
	//}
	//
	//kind := reflect.TypeOf(conn)
	//
	//if kind.Kind() == reflect.TypeOf(redisConnection.Conn).Kind() {
	//
	//}

	return nil, nil
}

func (redis Redis) createConnection() (io.Closer, error) {

	address := redis.Config.TokenAddress

	conn, err := redisConnection.Dial("tcp", address)
	if err != nil {
		fmt.Println("connect redis error :", err)
		return nil, err
	}
	defer conn.Close()
	return conn, err
}
